<?php
/**
 * Created by PhpStorm.
 * User: zy-l
 * Date: 2019/6/19
 * Time: 1:23 AM
 */
namespace App\HttpController\Admin;

use App\HttpController\AdminBase;
use App\Model\UcenterMember;
use EasySwoole\Validate\Validate;

/**
 * 行为日志管理
 * Class Adv
 * @package App\HttpController\Admin
 */
class Actionlog extends AdminBase
{

    /**
     * 行为模型
     * @return \App\Model\Action
     */
    public function getActionModel(){
        return new \App\Model\Action();
    }

    /**
     * 行为日志模型
     * @return \App\Model\ActionLog
     */
    public function getActionLogModel(){
        return new \App\Model\ActionLog();
    }

    /**
     * 用户模型
     * @return UcenterMember
     */
    public function getUcenterMemberModel(){
        return new UcenterMember();
    }
    /**
     * 行为日行
     * @return mixed
     */
    public function index()
    {
        if ($this->isPost()) {
            $where=array();
            $action_id=$this->postParam("action_id");
            if(!empty($action_id)){
                $where["action_id"]=$action_id;
            }
            $actionArr=$this->getActionModel()->getFiledColumnValue([],'id','title');
            $list=$this->getActionLogModel()->getPageAll($this->getActionLogModel()->analysisWhere($where));
            foreach ($list['list'] as $k=>$v){
                $list['list'][$k]['account'] = $this->getUcenterMemberModel()->getAccountByUid($v['user_id']);
                $list['list'][$k]['action_name'] = $actionArr[$v['action_id']];
            }
            return $this->writePageJson('数据列表',$list);
        }
        $actionList=$this->getActionModel()->getAll([],'id,title');
        $this->assign(['actionList'=>$actionList]);
        return $this->fetch();
    }

    /**
     * 删除
     * @param Request $request
     * @return mixed
     */
    public function del(Request $request){
        if ($request->isPost()) {
            return $this->actionLog->delData(["id"=>$request->param("id")]);
        }
    }
    /**
     * 提交参数验证
     * @param string|null $action
     * @return Validate|null
     */
    protected function getValidateRule(?string $action): ?Validate
    {
        $validate = null;
        return $validate;
    }
}